package com.leisurexi.aop.features;

import com.leisurexi.aop.features.interceptor.EchoServiceMethodInterceptor;
import com.leisurexi.aop.overview.DefaultEchoService;
import com.leisurexi.aop.overview.EchoService;
import org.springframework.aop.framework.ProxyFactory;

/**
 * @author: leisurexi
 * @date: 2021-05-21 16:19
 */
public class ProxyFactoryDemo {

    public static void main(String[] args) {
        EchoService target = new DefaultEchoService();
        // 注入目标对象 (被代理)
        ProxyFactory proxyFactory = new ProxyFactory(target);
        // 添加 Advice 实现 MethodInterceptor <- Interceptor <- Advice
        proxyFactory.addAdvice(new EchoServiceMethodInterceptor());
        // 获取代理对象
        EchoService echoService = (EchoService) proxyFactory.getProxy();
        System.out.println(echoService.echo("Hello, World"));
    }

}
